﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Register.IDAL;
using Register.Model;
using System.Data;
using Register.DBUtility;
using System.Data.SqlClient;

namespace Register.DAL
{
    /// <summary>
    /// FileName: HospitalInfoDAL.cs
    /// CLRVersion: 4.0.30319.269
    /// Author: WangYan
    /// Corporation: 
    /// Description: 
    /// DateTime: 2012/6/26 12:59:41
    /// </summary>
   public class HospitalInfoDAL:IHospitalInfoDAL
    {

        public List<Model.HospitalInfo> GetHospitalInfos()
        {
            String sql = " select * from System_hospitalInfo where Hospital_State='1' ";
            return DataSetToList(DbHelperSQL.Query(sql));
        }

        private List<HospitalInfo> DataSetToList(DataSet ds)
        {
            List<HospitalInfo> modelList = new List<HospitalInfo>();
            DataTable dt = ds.Tables[0];
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HospitalInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HospitalInfo();
                    model.Hospital_ID = dt.Rows[n]["Hospital_ID"].ToString();
                    model.City_ID = dt.Rows[n]["City_ID"].ToString();
                    model.Hospital_No = dt.Rows[n]["Hospital_No"].ToString();
                    model.Hospital_Name = dt.Rows[n]["Hospital_Name"].ToString();
                    model.Hospital_Level = dt.Rows[n]["Hospital_Level"].ToString();
                    model.Hospital_Nature = dt.Rows[n]["Hospital_Nature"].ToString();
                    model.Hospital_Type = dt.Rows[n]["Hospital_Type"].ToString();
                    model.Hospital_Address = dt.Rows[n]["Hospital_Address"].ToString();
                    model.Hospital_Phone = dt.Rows[n]["Hospital_Phone"].ToString();
                    model.Hospital_Website = dt.Rows[n]["Hospital_Website"].ToString();
                    model.Hospital_Introduce = dt.Rows[n]["Hospital_Introduce"].ToString();
                    model.Hospital_Logo = dt.Rows[n]["Hospital_Logo"].ToString();
                    if (dt.Rows[n]["Hospital_AddTime"].ToString() != "")
                    {
                        model.Hospital_AddTime = DateTime.Parse(dt.Rows[n]["Hospital_AddTime"].ToString());
                    }
                    model.Hospital_Recoder = dt.Rows[n]["Hospital_Recoder"].ToString();
                    if (dt.Rows[n]["Hospital_LastAmendTime"].ToString() != "")
                    {
                        model.Hospital_LastAmendTime = DateTime.Parse(dt.Rows[n]["Hospital_LastAmendTime"].ToString());
                    }
                    model.Hospital_LastAmendPerson = dt.Rows[n]["Hospital_LastAmendPerson"].ToString();
                    model.Hospital_State = dt.Rows[n]["Hospital_State"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        public HospitalInfo GetHospitalInfoByID(string Hospital_ID)
        {
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 Hospital_ID,City_ID,Hospital_No,Hospital_Name,Hospital_Level,Hospital_Nature,Hospital_Type,Hospital_Address,Hospital_Phone,Hospital_Website,Hospital_Introduce,Hospital_Logo,Hospital_AddTime,Hospital_Recoder,Hospital_LastAmendTime,Hospital_LastAmendPerson,Hospital_State from System_hospitalInfo ");
			strSql.Append(" where Hospital_ID=@Hospital_ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@Hospital_ID", SqlDbType.Char,5)};
			parameters[0].Value = Hospital_ID;

            HospitalInfo model = new HospitalInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["Hospital_ID"]!=null)
				{
				model.Hospital_ID=ds.Tables[0].Rows[0]["Hospital_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["City_ID"]!=null)
				{
				model.City_ID=ds.Tables[0].Rows[0]["City_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_No"]!=null)
				{
				model.Hospital_No=ds.Tables[0].Rows[0]["Hospital_No"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Name"]!=null)
				{
				model.Hospital_Name=ds.Tables[0].Rows[0]["Hospital_Name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Level"]!=null)
				{
				model.Hospital_Level=ds.Tables[0].Rows[0]["Hospital_Level"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Nature"]!=null)
				{
				model.Hospital_Nature=ds.Tables[0].Rows[0]["Hospital_Nature"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Type"]!=null)
				{
				model.Hospital_Type=ds.Tables[0].Rows[0]["Hospital_Type"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Address"]!=null)
				{
				model.Hospital_Address=ds.Tables[0].Rows[0]["Hospital_Address"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Phone"]!=null)
				{
				model.Hospital_Phone=ds.Tables[0].Rows[0]["Hospital_Phone"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Website"]!=null)
				{
				model.Hospital_Website=ds.Tables[0].Rows[0]["Hospital_Website"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Introduce"]!=null)
				{
				model.Hospital_Introduce=ds.Tables[0].Rows[0]["Hospital_Introduce"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_Logo"]!=null)
				{
				model.Hospital_Logo=ds.Tables[0].Rows[0]["Hospital_Logo"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_AddTime"].ToString()!="")
				{
					model.Hospital_AddTime=DateTime.Parse(ds.Tables[0].Rows[0]["Hospital_AddTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Hospital_Recoder"]!=null)
				{
				model.Hospital_Recoder=ds.Tables[0].Rows[0]["Hospital_Recoder"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_LastAmendTime"].ToString()!="")
				{
					model.Hospital_LastAmendTime=DateTime.Parse(ds.Tables[0].Rows[0]["Hospital_LastAmendTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Hospital_LastAmendPerson"]!=null)
				{
				model.Hospital_LastAmendPerson=ds.Tables[0].Rows[0]["Hospital_LastAmendPerson"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Hospital_State"]!=null)
				{
				model.Hospital_State=ds.Tables[0].Rows[0]["Hospital_State"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		
        }
    }
}
